package com.rybbaby.tss.core.utils;


import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.rybbaby.tss.core.enums.ReceiptTypeEnum;
import com.rybbaby.tss.front.tssPertainRelation.entity.TssPertainRelation;
import net.sf.json.JSON;
import net.sf.json.JSONSerializer;

import javax.json.Json;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


public class CodeGenUtil  {

    /**
     * 生成编码
     *
     * @param sequenceName 序列名称
     * @param sign         签名字符串
     * @param randomStr    参与签名的随机字符串
     * @param timestamp    参与签名的时间戳
     * @param size         生成个数，不传或传入1按单个生成
     * @return
     */

    /**
     * 请求UMS统一生成编码规则
     */
    public static String  getCodeGen(Map<String,Object> paramsMap) {

        String resultJson="";

        try {
            //String url = "http://localhost:8084/code/gen";
             String url = "http://192.168.0.4:8180/api/gateway/common/codeGen";
            //时间戳
            long timestamp = System.currentTimeMillis();
            //随机字符串
            String randomStr = SequenceUtil.getOriginalUUID();

            //业务参数列表
            paramsMap.put("clientKey", "700B05A31CA94AB39E7D5ABF60B89DD3");

            //根据参数生成签名
            String sign = SignUtil.genSign(paramsMap, timestamp, randomStr);
            //将签名纳入参数
            paramsMap.put("sign", sign);
            //将参与生成签名的时间戳和随机字符串纳入参数
            paramsMap.put("timestamp", timestamp);
            paramsMap.put("randomStr", randomStr);


            Object result = HttpUtil.httpGet(url, paramsMap, HttpUtil.ReturnType.String);
            resultJson = JSONSerializer.toJSON(result).toString();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return resultJson;
    }

    public static void main(String[] args) {
        Map<String,Object> map=new HashMap<>();
        String  s= getCodeGen(map);
        Gson gson=new Gson();
        Map relationList = gson.fromJson(s, new TypeToken<Map>() {}.getType());
        System.out.println(relationList.get("data"));
    }


}
